*******************************************************************
*******************************************************************
*Brown Mettler "Polarizing by Place" _Perspectives on Politics_ Repbulication File*
*******************************************************************
*******************************************************************

**Set working directory to PoP_Republication file**
cd "/Users/trevorbrown/Downloads/BrownMettler_PoP_Replication_FirstRelease"

*******************************************************************
*Section 1: Descriptive Figures*
*******************************************************************

**Import descriptive data and label variables**
import delimited "brownmettler_PoP_aggregatedescriptives.csv", clear
gen repvotesharerural = totalrepvoteshare if rurality == "Rural"
gen repvoteshareurban = totalrepvoteshare if rurality == "Urban"
gen differencesouth = ruralurbandiff if regionname == "South"
gen differencenortheast = ruralurbandiff if regionname == "Northeast"
gen differencewest = ruralurbandiff if regionname == "West"
gen differencemidwest = ruralurbandiff if regionname == "Midwest"
gen ruraljobspercap = employpercap if rurality == "Rural"
gen urbanjobspercap = employpercap if rurality == "Urban"
gen ruralpopulation = population if rurality == "Rural"
gen urbanpopulation = population if rurality == "Urban"
gen ruralcollegeshare = collegeshare if rurality == "Rural"
gen urbancollegeshare = collegeshare if rurality == "Urban"
gen ruralsharenonwhite = sharenonwhite if rurality == "Rural"
gen urbansharenonwhite = sharenonwhite if rurality == "Urban"
gen ruralsharehispanic = sharehispanic if rurality == "Rural"
gen urbansharehispanic = sharehispanic if rurality == "Urban"
gen ruralsupportaidtoblack = supportaidtoblack if rurality == "Rural"
gen urbansupportaidtoblack = supportaidtoblack if rurality == "Urban"
lab var year "Year"
lab var election "Election"
lab var decade "Decade"
lab var repvotesharerural "Rural"
lab var repvoteshareurban "Urban"
lab var differencewest "West"
lab var differencemidwest "Midwest"
lab var differencenortheast "Northeast"
lab var differencesouth "South"
lab var ruraljobspercap "Rural"
lab var urbanjobspercap "Urban"
lab var ruralpopulation "Rural"
lab var urbanpopulation "Urban"
lab var ruralcollegeshare "Rural"
lab var urbancollegeshare "Urban"
lab var ruralsupportaidtoblack "Rural"
lab var urbansupportaidtoblack "Urban"
lab var ruralsharenonwhite "Rural"
lab var urbansharenonwhite "Urban"
lab var ruralsharehispanic "Rural"
lab var urbansharehispanic "Urban"

**Graph figures 1-8 (All exported to file "BrownMettler_PoP_Replication" file as .pngs)**

*Figure 1: Rural-Urban Presidential Voting, Over Time*
twoway scatter repvotesharerural repvoteshareurban election, title("Figure 1: The Rural-Urban Divide in Presidential Voting", color(black)) ytitle("Share of Votes Going to Republican Candidate (County-Level)", color (black)) xlabel(1972(4)2020)  ///
ms(O t) mcolor(black gs8) mlabel(repvotesharerural repvoteshareurban) mlabcolor(black gs8) ///
connect(l l) lcolor(black gs8) lpattern(dash solid) ///
graphregion(color(white)) bgcolor(white) 
graph export "brownmettler_pop_figure1final.png", replace


*Figure 2: Regional Rural-Urban Presidential Voting Patterns*
scatter differencemidwest differencenortheast differencesouth differencewest  election, title("Figure 2: The Rural-Urban Divide in Presidential Voting, by Region", color(black)) ytitle("County-Level Rural-Urban Vote Share Difference (Full Percentage Points)", color (black)) xlabel(1972(4)2020) ylab(-10(5)20)  ///
ms(O t square plus) mcolor(black black black black) ///
connect(l l l l) lcolor(black black black black) lpattern(dash dash_dot dot solid) ///
graphregion(color(white)) bgcolor(white) 
graph export "brownmettler_pop_figure2final.png", replace
 
*Figure 3: Rural-Urban Divide in Employment Per Capita*
scatter ruraljobspercap urbanjobspercap  year, title("Figure 3: Employment Per Capita, Over Time", color(black)) ytitle("Number of Jobs Per Person", color (black)) mlabcolor(black black) xlabel(1972(4)2020) ///
ms(O t) mcolor(black gs8) mlabel(ruraljobspercap urbanjobspercap)  ///
connect(l l) lcolor(black gs8) lpattern(dash solid) ///
graphregion(color(white)) bgcolor(white) 
graph export "brownmettler_pop_figure3final.png", replace
 
*Figure 4: Rural-Urban Divide in Raw Population Growth*
scatter ruralpopulation urbanpopulation  decade, title("Figure 4: Raw Population Growth, Over Time", color(black)) ytitle("Raw Population", color (black)) mlabcolor(black black) xlabel(1970(10)2020) ylabel("") ///
ms(O t) mcolor(black gs8) mlabel(ruralpopulation urbanpopulation)  ///
connect(l l) lcolor(black gs8) lpattern(dash solid) ///
graphregion(color(white)) bgcolor(white) 
graph export "brownmettler_pop_figure4final.png", replace

 
*Figure 5: Rural-Urban Divide in Educational Attainment*
scatter ruralcollegeshare urbancollegeshare decade, title("Figure 5: The Rural-Urban Education Divide, Over Time", color(black)) ytitle("Share of Population 25+ with a Four-Year Degree", color (black)) mlabcolor(black black) ///
ms(O t) mcolor(black gs8) mlabel(ruralcollegeshare urbancollegeshare)  ///
connect(l l) lcolor(black gs8) lpattern(dash solid) ///
graphregion(color(white)) bgcolor(white) 
graph export "brownmettler_pop_figure5final.png", replace

*Figure 6: Racial Animus / Support for Gov't Aid to Black Americans, by Rurality Over Time* 	
twoway scatter ruralsupportaidtoblack urbansupportaidtoblack year, con(l l) xlabel(1976(4)2020) lcolor(black gs8) lpattern(dash solid)  ms(O t) mcolor(black gs8) mlabcolor(black black) mlabel(ruralsupportaidtoblack urbansupportaidtoblack) xlabel(1976(4)2020)  || rcap ciupperbound cilowerbound year, lcolor(black) title("Figure 6: Racial Animus by Rurality, Over Time", color(black)) ytitle("Support for Gov't Aid to Black Americans", color (black)) ylabel(0(10)100) ///
mlabel(ruralsupportaidtoblack urbansupportaidtoblack)  ///
connect(l l) ///
graphregion(color(white)) bgcolor(white) ///
legend(order(1 "Rural" 2 "Urban")) 
graph export "brownmettler_pop_figure6final.png", replace

*Figure 7: Share of Population ID'ing as Nonwhite, by Rurality and Over Time*
scatter ruralsharenonwhite urbansharenonwhite decade, title("Figure 7: Share of Population Identifying as Nonwhite, Over Time", color(black)) ytitle("", color (black)) mlabcolor(black black) ///
ms(O t) mcolor(black gs8) mlabel(ruralsharenonwhite urbansharenonwhite)  ///
connect(l l) lcolor(black gs8) lpattern(dash solid) ///
graphregion(color(white)) bgcolor(white) 
graph export "brownmettler_pop_figure7final.png", replace

 
*Figure 8: Share of Population ID'ing as Hispanic, by Rurality and Over Time*
scatter ruralsharehispanic urbansharehispanic decade, title("Figure 8: Share of Population Identifying as Hispanic, Over Time", color(black)) ytitle("", color (black)) mlabcolor(black black) ///
ms(O t) mcolor(black gs8) mlabel(ruralsharehispanic urbansharehispanic)  ///
connect(l l) lcolor(black gs8) lpattern(dash solid) ///
graphregion(color(white)) bgcolor(white) 
graph export "brownmettler_pop_figure8final.png", replace

*******************************************************************
*******************************************************************
*End*
*******************************************************************
*******************************************************************
